/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2014 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

//***********************************************************************************************************
//  Nuvoton Technology Corp.
//  Date: 23/Jan/2014
//  E-Mail: MicroC-8bit@nuvoton.com
//***********************************************************************************************************

#include <stdio.h>
#include "N79E81x.h"
#include "Typedef.h"
#include "Define.h"
#include "Common.h"
#include "Delay.h"
#include <intrins.h>

    #define VALUE_10us    65536-18      //18*12/22.1184 = 10 us
    #define VALUE_1ms     65536-1843    //1843*12/22.1184 = 1 ms

//-------------------------------------------------------------------------
void Delay10us(UINT16 u16CNT)
{
    TR0 = 1;
    while (u16CNT != 0)
    {
        TL0 = LOBYTE(VALUE_10us);
        TH0 = HIBYTE(VALUE_10us);
        while (TF0 != 1);
        TF0 = 0;
        u16CNT --;
    }
    TR0 = 0;
}
//------------------------------------------------------------------------------
void Delay1ms(UINT32 u32CNT)
{
    TR0 = 1;
    while (u32CNT != 0)
    {
        TL0 = LOBYTE(VALUE_1ms);
        TH0 = HIBYTE(VALUE_1ms);
        while (TF0 != 1);
        TF0 = 0;
        u32CNT --;
    }
    TR0 = 0;
}
 void Delay1ms2(UINT8 u32CNT)
{
   TR1 = 1;
    while (u32CNT != 0)
    {
        TL1 = LOBYTE(VALUE_1ms);
        TH1 = HIBYTE(VALUE_1ms);
        while (TF1 != 1);
        TF1 = 0;
        u32CNT --;
    }
    TR1 = 0;
}

